#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Run the simulation with a limited number of time steps.
This is useful for quick testing without running the full simulation.
"""

import sys
import os

# Add the project root to the Python path
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if PROJECT_ROOT not in sys.path:
    sys.path.append(PROJECT_ROOT)

import argparse

# Parse command line arguments
parser = argparse.ArgumentParser(description='Run dragonfly simulation with limited steps')
parser.add_argument('--steps', type=int, default=50, help='Maximum number of time steps (default: 50)')
parser.add_argument('--output-freq', type=int, default=10, help='Output frequency (default: 10)')
args = parser.parse_args()

# Temporarily modify config before importing other modules
import config

# Calculate simulation time for the desired number of steps
desired_steps = args.steps
config.SIMULATION_TIME = desired_steps * config.TIME_STEP_SIZE
config.OUTPUT_FREQUENCY = args.output_freq

print("="*60)
print("Running LIMITED STEPS simulation")
print("="*60)
print(f"Time steps: {desired_steps}")
print(f"Time step size: {config.TIME_STEP_SIZE:.6f}s")
print(f"Total simulation time: {config.SIMULATION_TIME:.6f}s")
print(f"Output frequency: every {config.OUTPUT_FREQUENCY} steps")
print("="*60)
print()

# Now import and run the main simulation
sys.path.append(PROJECT_ROOT)
from main import run_simulation

try:
    run_simulation()
    print("\n" + "="*60)
    print(f"✓ Limited simulation ({desired_steps} steps) completed successfully!")
    print("="*60)
except KeyboardInterrupt:
    print("\n" + "="*60)
    print("✗ Simulation interrupted by user")
    print("="*60)
except Exception as e:
    print("\n" + "="*60)
    print(f"✗ Simulation failed with error: {e}")
    print("="*60) 